package com.sky.mapper;

import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 符健清
 * @version 1.0
 * 套餐  处理层
 */
@SuppressWarnings({"all"})
@Mapper
public interface SetMealServiceMapper {
    /**
     * 分页 条件查询
     * @param setmeal
     * @return
     */
    List<Setmeal> pageSelectSetmeal(Setmeal setmeal);

    /**
     *起售 /停售
     * @param status
     * @param id
     */
    @Update("update  setmeal   set status =#{status}  where id =#{id} ")
    void startAndStopSetmeal(@Param("status") Integer status,  @Param("id") Integer id);

    /**
     * 删除套餐
     * @param ids
     */
    void deleteSetmeal(List<Integer> ids);

    /**
     *添加套餐
     * @param setmeal
     */
    @Insert("INSERT INTO setmeal VALUES (NULL,#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser});")
    void inserSetmeal(Setmeal setmeal);

    /**
     * 根据 添加套餐的 name 获取id
     * @param name
     * @return
     */

    @Select("select  *from setmeal where  name =#{name}")
    List <Setmeal>  selectSetmealByName(String name);
    /**
     * 添加 套餐包含的菜品
     * @param setmealDish
     */
    @Insert("INSERT INTO setmeal_dish VALUES (NULL,#{setmealId},#{dishId},#{name},#{price},#{copies});")
    void insertSetmealDish(SetmealDish setmealDish);

    /**
     * 根据  id  查询   setmeal  套餐表格
     * @param id
     * @return
     */
    @Select("SELECT * FROM setmeal where id =#{id}")
    Setmeal selectSetmealById(Object id);

    /**
     * 根据 id 查询 setmeal_dish 套餐菜品表格
     * @param id
     * @return
     */
    @Select("SELECT * FROM setmeal_dish where id =#{id}")
    SetmealDish selectSetmealDishById(Integer id);

    /**
     * 修改setmeal  参数
     * @param setmeal
     */
    void updateSetmeal(Setmeal setmeal);

    /**
     * 修改 setmeal_dish 参数
     */
    void updateSetmealDish(SetmealDish setmealDish);

    /**
     * 根据 category_id  查询
     * @param id
     * @return
     */
    @Select("select * from setmeal where category_id =#{id}")
   List  < Setmeal > selectSetmealByCategory_id(Integer id);


    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
